package com.example.flutter_demo2.utils

import android.app.Activity
import android.os.Build
import android.view.View
import android.view.Window
import android.view.WindowManager

object CommonUtil {
    // maybe no use
    fun hideSysUi(isHide: Boolean, activity: Activity) {
        val view = activity.window.decorView
        if (isHide) {
            view.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
        } else {
            // show immersive
            if (isSpecialMobile()) {
                activity.window.setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN
                )
            }
            view.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
        }
    }

    private fun isSpecialMobile(): Boolean {
        return Build.BRAND == "OPPO" && Build.DEVICE == "A33"
    }

    /**
     * 设置隐藏标题栏
     *
     * @param activity
     */
    fun setNoTitleBar(activity: Activity) {
        activity.requestWindowFeature(Window.FEATURE_NO_TITLE)
    }

    /**
     * 设置全屏
     *
     * @param activity
     */
    fun setFullScreen(activity: Activity) {
        activity.window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }

    /**
     * 取消全屏
     *
     * @param activity
     */
    fun cancelFullScreen(activity: Activity) {
        activity.window.clearFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN
        )
    }
}